package com.css.modules.lawRepo.controller;

import com.css.common.utils.PageUtils;
import com.css.common.utils.R;
import com.css.modules.lawRepo.entity.LawRepoLegalCategoryTEntity;
import com.css.modules.lawRepo.service.LawRepoLegalCategoryTService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/lawRepo/legalCategory")
@Api(value = "/legalCategory", description = "法律法规类别表", tags = "法律法规类别表")
public class LawRepoLegalCategoryTController {
    @Autowired
    private LawRepoLegalCategoryTService lawRepoLegalCategoryTService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数", dataType = "int", paramType = "query", required = true),
    })
    @RequestMapping(value = "/list" ,method = RequestMethod.GET)
    @ApiOperation(value = "法律法规类别表", notes = "法律法规类别表",
            produces = "application/json")
    public R list(@ApiParam(name="params" ,hidden = true)@RequestParam Map<String, Object> params){
        PageUtils page = lawRepoLegalCategoryTService.queryPage(params);
        return R.ok().put("page", page);
    }

    @ApiOperation(value = "根据关键字查询", produces = "application/json")
    @RequestMapping(value = "/findByKeywords{keywords}" ,method = RequestMethod.GET)
    public LawRepoLegalCategoryTEntity findByKeywords(@RequestParam("keywords") String keywords){
        return lawRepoLegalCategoryTService.findByKeywords(keywords);
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "添加法律法规类别", produces = "application/json")
    public R insert(@RequestBody LawRepoLegalCategoryTEntity entity){
        lawRepoLegalCategoryTService.insert(entity);
        return R.ok();
    }

    @PostMapping("/deleteBatch")
    @ApiOperation(value = "批量删除", produces = "application/json")
    @ApiImplicitParam(name = "mapIds",value = "ids",paramType = "body",dataType = "body")
    public R deleteBatch(@RequestBody Map<String, Object> mapIds) {
        lawRepoLegalCategoryTService.commonUpdateDelFlagBatch("1", mapIds);
        return R.ok();
    }

    @ApiOperation(value = "根据id查询所有子类", produces = "application/json")
    @RequestMapping(value = "/findChildrenById{uuid}", method = RequestMethod.GET)

    public List<LawRepoLegalCategoryTEntity> findChildrenById(@RequestParam("uuid")String uuid){

        return lawRepoLegalCategoryTService.findAllChildren(uuid);

    }

    @ApiOperation(value = "根据法律法规名查询所有子类", produces = "application/json")
    @RequestMapping(value = "/findChildrenByName{name}", method = RequestMethod.GET)

    public List<LawRepoLegalCategoryTEntity> findChildrenByName(@RequestParam("name")String name){

        return lawRepoLegalCategoryTService.findChildrenByName(name);

    }





}
